package com.example.day02.startfrag;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.day02.R;
import com.example.day02.utils.AssetsUtils;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class StarImgInfoActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "StarImgInfoActivity";
    ImageView backIv;
    TextView titleTv;
    TextView tv;
    List<ImageView>imglist;
    List<TextView>starList;
    int[]imgIds={R.mipmap.a,R.mipmap.b,R.mipmap.c,R.mipmap.d,
            R.mipmap.e,R.mipmap.f,R.mipmap.g,R.mipmap.h,
            R.mipmap.i,R.mipmap.j,R.mipmap.k,R.mipmap.l};
    String[]star={"白羊座","金牛座","双子座","巨蟹座",
            "狮子座","处女座","天秤座","天蝎座",
            "射手座","摩羯座","水瓶座","双鱼座"};
    private StarImgInfoAdapter adapter;
    ViewPager imgVp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_star_img_info);
        backIv=findViewById(R.id.title_iv_back);
        titleTv=findViewById(R.id.title_tv);
        backIv.setOnClickListener(this);
        imgVp=findViewById(R.id.star_img_vp);
        imglist=new ArrayList<>();
        for (int i = 0; i <imgIds.length ; i++) {
            ImageView iv = new ImageView(this);
            iv.setImageResource(imgIds[i]);//设置现实的图片
            iv.setScaleType(ImageView.ScaleType.FIT_XY);//显示样式
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            iv.setLayoutParams(lp);//宽高
            imglist.add(iv);
        }
        for (int i = 0; i <star.length ; i++) {
            String name="";
            name=star[i];
            Log.d(TAG, "name: "+name);
        }
        titleTv.setText("("+star[0]+"1/"+star.length+")");
        adapter = new StarImgInfoAdapter(this, imglist);
        imgVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
              titleTv.setText("("+star[position]+(position+1)+"/"+star.length+")");
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        imgVp.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.title_iv_back:
                finish();
                break;
        }
    }
}
